package com.hitqz.robot.biz.flow.domain.common;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * 响应结果-通用返回类
 *
 * @author wengyx
 * @date 2023/08/23
 */
@Data
public class ResponseResult<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1047250314958115086L;
    private Integer code;
    private String message;
    private T data;

    public ResponseResult() {
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static ResponseResult<?> success() {
        return new ResponseResult<>(FailedCodeEnum.SUCCESS.getCode(), FailedCodeEnum.SUCCESS.getMsg());
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(FailedCodeEnum.SUCCESS.getCode(), FailedCodeEnum.SUCCESS.getMsg(), data);
    }

    public static ResponseResult<?> fail() {
        return new ResponseResult<>(FailedCodeEnum.FAILED.getCode(), FailedCodeEnum.FAILED.getMsg());
    }

    public static ResponseResult<?> fail(FailedCodeEnum codeEnum) {
        return new ResponseResult<>(codeEnum.getCode(), codeEnum.getMsg());
    }

    public static <T> ResponseResult<T> fail(FailedCodeEnum codeEnum, T data) {
        return new ResponseResult<>(codeEnum.getCode(), codeEnum.getMsg(), data);
    }
}
